home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Environments / MacCjr / MacC Jr / FileDemo Folder / FileDemo.c next >
Encoding:
C/C++ Source or Header  |  1987-01-05  |  1.3 KB  |  48 lines  |  [TEXT/EDIT]

  1. // FileDemo.c
  2. // © Copyright 1987 Consulair Corp    All Rights Reserved.
  3. // This example shows how to read and write files using 
  4. // standard C constructs with added Macintosh features.
  5. // The MacC Jr. Library allows you to fopen a file using
  6. // the Macintosh Standard File convention.  The first 18 lines 
  7. // of the file are then written to the output file and screen.
  8.  
  9. #include <stdio.h>
  10.  
  11. extern char *_SF_Name;        // Name of opened file
  12. extern short _SF_vRefNum;    // Where it opens
  13. main()
  14.  {
  15.  char c, inFileName[63];
  16.  short invRefNum;
  17.  int i, i1, linecount;
  18.  FILE *file, *outfile;
  19.  if (file = fopen(".SFin", "R"))
  20.    {
  21.    strcpy(inFileName, _SF_Name);
  22.    invRefNum = _SF_vRefNum;
  23.    if (outfile = fopen(".SFout", "W"))
  24.      {
  25.      printf("\rInput File: %s [vRefNum = %4X]", inFileName, invRefNum);
  26.      printf("\rOutput File: %s [vRefNum = %4X]", _SF_Name, _SF_vRefNum);
  27.      getchar();
  28.      printf("\r");
  29.      linecount = 0;
  30.      while(!feof(file))
  31.        {
  32.        if ((c = fgetc(file)) == '\n') 
  33.      if (++linecount > 18) break;
  34.        putchar(c);
  35.        fputc(c, outfile);
  36.        }
  37.      fclose(outfile);
  38.      setFileType(_SF_Name, 'TEXT');
  39.      setFileCreator(_SF_Name, 'EDIT');
  40.      }
  41.    else printf("\rCould Not Open Output");
  42.    fclose(file);
  43.    }
  44.  else printf("\rCould Not Open Input");
  45.  getchar();
  46.  }
  47.  
  48.